package com.global.college;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.global.college.base.BaseApplication;
import com.global.college.constants.Constant;

import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

/**
 * @author fzw
 * @date 2021/9/13 0013.
 * email：
 * description：
 */
public class CollegeApplication extends BaseApplication {

    private IWXAPI mWxApi;

    private static CollegeApplication instance;

    //私有构造器
    public static CollegeApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initWeChat();
        // TODO: 2022/1/4 umeng初始化，需重新申请应用，当前复制nft
//        UMConfigure.preInit(this,"61974913e0f9bb492b6534fc",getChannel());
    }

    public String getChannel() {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = null;
        try {
            appInfo = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
            return appInfo.metaData.getString("UMENG_CHANNEL_VALUE");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    private void initWeChat() {
        mWxApi = WXAPIFactory.createWXAPI(this, Constant.WECHAT_PAY_APP_ID, true);
        // 将该app注册到微信
        mWxApi.registerApp(Constant.WECHAT_PAY_APP_ID);
    }

    public IWXAPI getmWxApi() {
        return mWxApi;
    }
}
